﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections.ObjectModel;
using System.Collections;
using System.Collections.Concurrent;
using log4net;

namespace EquipmentConfig.Class
{
    public class Messages
    {

        /// <summary>
        /// 显示信息
        /// </summary>
        /// <param name="msg">信息</param>
        public static void ShowMessage(string msg)
        {
            MessageBox.Show(msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        /// <summary>
        /// 记录Log
        /// </summary>
        /// <param name="exp">Exception 对象</param>
        public static void SaveLog(Exception exp)
        {
            string strErrMsg = exp.Message + "\r\n";
            strErrMsg = strErrMsg + "Source:" + exp.Source.ToString() + "\r\n";
            strErrMsg = strErrMsg + "StackTrace:" + exp.StackTrace;
            SaveLog(strErrMsg, ELogType.Fatal);

        }
        public static void SaveLog(Exception exp, ELogType logType)
        {
            string strErrMsg = exp.Message + "\r\n";
            strErrMsg = strErrMsg + "Source:" + exp.Source.ToString() + "\r\n";
            strErrMsg = strErrMsg + "StackTrace:" + exp.StackTrace;
            SaveLog(strErrMsg, logType);
        }

        public static void SaveLog(Exception exp, ELogLayer logLayer)
        {
            string strErrMsg = exp.Message + "\r\n";
            strErrMsg = strErrMsg + "Source:" + exp.Source.ToString() + "\r\n";
            strErrMsg = strErrMsg + "StackTrace:" + exp.StackTrace;
            Logging.SaveLog(logLayer, strErrMsg, ELogType.Error);
        }

        public static void SaveLog(Exception exp, ELogLayer logLayer, ELogType logType)
        {
            string strErrMsg = exp.Message + "\r\n";
            strErrMsg = strErrMsg + "Source:" + exp.Source.ToString() + "\r\n";
            strErrMsg = strErrMsg + "StackTrace:" + exp.StackTrace;
            Logging.SaveLog(logLayer, strErrMsg, logType);
        }

        public static void SaveLog(string sMsg, ELogLayer logLayer, ELogType logType)
        {
            Logging.SaveLog(logLayer, sMsg, logType);
        }

        public static void SaveLog(string sMsg)
        {
            SaveLog(sMsg, ELogType.Fatal);
        }

        public static void SaveLog(string sMsg, ELogType logType)
        {
            Logging.SaveLog(ELogLayer.UI, sMsg, logType);
        }

        /// <summary>
        /// 记录Log并提示
        /// </summary>
        /// <param name="exp">Exception对象</param>
        public static void SaveLogDialog(Exception exp)
        {
            SaveLog(exp);
            ShowAlertDialog(false);
        }

        /// <summary>
        /// 记录Log并提示
        /// </summary>
        /// <param name="exp">Exception对象</param>
        /// <param name="alertMsg">信息字符串</param>
        public static void SaveLogDialog(string alertMsg, Exception exp)
        {
            SaveLog(exp);
            ShowAlertDialog(alertMsg, false);
        }

        /// <summary>
        ///弹出自定义提示讯息
        /// </summary>
        /// <param name="alertMsg">信息字符串</param>
        /// <param name="successorfail">成功或失败</param>
        public static void ShowAlertDialog(bool successorfail)
        {
            if (successorfail)
            {
                MessageBox.Show("操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("操作失败!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        /// <summary>
        ///弹出自定义提示讯息
        /// </summary>
        /// <param name="alertMsg">信息字符串</param>
        /// /// <param name="successorfail">成功或失败</param>
        public static void ShowAlertDialog(string alertMsg, bool successorfail)
        {
            if (successorfail)
            {
                MessageBox.Show(alertMsg, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show(alertMsg, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}